import axios from "axios";
// const API_ROOT: string = IS_DEV
//   ? "http://localhost:3009/api/"
//   : "https://blogapi.naice.me/api/";
const host = "http://10.3.144.31:2103";

const instance = axios.create({
  // baseURL: 基础路径
  baseURL: host + "/api",
});

instance.host = host;

// 请求拦截 每个请求都会走这里
instance.interceptors.request.use(
  function (config) {
    // console.log("config", config);
    // Do something before request is sent
    let userInfo = localStorage.getItem("userInfo");
    try {
      userInfo = JSON.parse(userInfo) || {};
    } catch (err) {
      userInfo = {};
    }
    if (userInfo.Authorization) {
      config.headers.Authorization = userInfo.Authorization;
    }
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

export default instance;
